<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>shell 练习-统计分析日志 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>shell 练习-统计分析日志</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/shell练习/">shell练习</a>
			</span>
		
	</div>

	

	
		<p>已知nginx访问的日志文件在/usr/local/nginx/logs/access.log内</p>
<p>请统计下早上10点到12点 来访ip最多的是哪个?</p>
<p>日志样例：</p>
<blockquote>
<p>111.199.186.68 - [15/Sep/2017:09:58:37 +0800]  “//plugin.php?id=security:job” 200 “POST //plugin.php?id=security:job HTTP/1.1””<a href="http://a.lishiming.net/forum.php?mod=viewthread&amp;tid=11338&amp;extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline" target="_blank" rel="external">http://a.lishiming.net/forum.php?mod=viewthread&amp;tid=11338&amp;extra=page%3D1%26filter%3Dauthor%26orderby%3Ddateline</a>“ “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3141.7 Safari/537.36” “0.516”<br>203.208.60.208 - [15/Sep/2017:09:58:46 +0800] “/misc.php?mod=patch&amp;action=ipnotice&amp;_r=0.05560809863330207&amp;inajax=1&amp;ajaxtarget=ip_notice” 200 “GET /misc.php?mod=patch&amp;action=ipnotice&amp;_r=0.05560809863330207&amp;inajax=1&amp;ajaxtarget=ip_notice HTTP/1.1””<a href="http://a.lishiming.net/forum.php?mod=forumdisplay&amp;fid=65&amp;filter=author&amp;orderby=dateline" target="_blank" rel="external">http://a.lishiming.net/forum.php?mod=forumdisplay&amp;fid=65&amp;filter=author&amp;orderby=dateline</a>“ “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3141.7 Safari/537.36” “0.065”</p>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">grep <span class="string">'15/Sep/2017:1[0-2]:[0-5][0-9]:'</span> /usr/<span class="built_in">local</span>/nginx/logs/access.log|awk <span class="string">'&#123;print $1&#125;'</span>|sort -n|uniq -c |tail -n1</div></pre></td></tr></table></figure>
	

	
		<span class="different-posts"><a href="/2017/10/12/Shell 练习/60.shell 练习-统计分析日志/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
